package cn.gov.cbrc.core.servlet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gov.cbrc.core.util.PropertiesUtil;

/**
 * Servlet implementation class DeleteLogByName
 */
public class DeleteLogByName extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteLogByName() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String logName = request.getParameter("logName");
		String logPath = PropertiesUtil.getProperty("logPath");
		String path = logPath+"/"+logName;
		File logFile = new File(path);
		boolean isDeleted = false;
		if(logFile.exists()){
			isDeleted = logFile.delete();
		}else{
			isDeleted = true;
		}
		out.print(isDeleted);
		out.flush();
		out.close();
	}

}
